package org.lex.notepad.ui.action.edit;

import java.awt.event.ActionEvent;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

import javax.swing.KeyStroke;

import org.lex.notepad.ui.NotepadEditor;
import org.lex.notepad.ui.action.BaseNotepadAction;

public class InsertDateTimeAction extends BaseNotepadAction {
	private DateFormat format = null;

	public InsertDateTimeAction() {
		super();
		this.setName("Data/Time");
		this.setAcceleratorKey(KeyStroke.getKeyStroke("F5"));
	}

	public void actionPerformed(ActionEvent e) {
		if (null == format)
			format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.getDefault());
		NotepadEditor editor = notepad.getEditor();
		int pos = editor.getCaretPosition();
		String time = format.format(new Date(System.currentTimeMillis()));
		editor.insert(time, pos);
	}
}
